/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package RestaurantManagement;

/**
 * Meal class for managing meals composed of ingredients
 * name: the meals name
 * Ingredients: list of ingrdients
 * @author ashongtical
 */

import java.util.*;
public class Meal implements Priceable {
    private String name;
    private ArrayList<Ingredient> ingredients;

    public Meal(String name) {
        this.name = name;
        this.ingredients = new ArrayList<>();
    }

    public String getName() {
        return this.name;
    }

    public void addIngredient(Ingredient ingredient) {
        ingredients.add(ingredient);
    }

    public ArrayList<Ingredient> getIngredients() {
        return this.ingredients;
    }

    @Override
    public double getPrice() {
        double sum = 0;
        for (Ingredient ingredient : ingredients) {
            sum += ingredient.getPrice();
        }
        return sum;
    }

    @Override
    public String toString() {
        String meal = this.name + " - RMB" + this.getPrice();
        String ingredientList = "";
        for(int i = 0; i < ingredients.size(); i++){
            if(i > 0){
                ingredientList += ", ";
            }
            ingredientList += this.ingredients.get(i).getName();
        }
        meal += "\nIngredients: " + ingredientList;
        return meal;
    }
}